#pragma once

#include <string>
#include <iostream>
#include <fstream>

namespace solver
{
	class file_data 
	{
		char *file_data_bytes;
		std::string file_name;

	public:

		file_data() : file_data_bytes( nullptr )
		{

		}

		file_data(const char *cnf_file_name) : file_data_bytes(nullptr)
		{			
			file_name = cnf_file_name;
			std::ifstream t;
			int length;
			t.open(file_name);      // open input file
			t.seekg(0, std::ios::end);    // go to the end
			length = t.tellg();           // report location (this is the length)
			if (length > -1) {
				t.seekg(0, std::ios::beg);    // go back to the beginning
				file_data_bytes = new char[length + 1];    // allocate memory for a buffer of appropriate dimension
				for (int i = 0; i < length + 1; i++) {
					file_data_bytes[i] = 0;
				}
				t.read(file_data_bytes, length);       // read the whole file into the buffer
			}
			else 
			{
				length = 0;
				file_data_bytes = new char[length + 1];
			}
			file_data_bytes[length] = 0;
			t.close();
		}

		virtual ~file_data()
		{
			if (file_data_bytes) {
				delete[] file_data_bytes;
				file_data_bytes = nullptr;
			}
		}

		const char *get_data()
		{
			return file_data_bytes;
		}

		const std::string& get_file_name()
		{
			return file_name;
		}

	};

}
